package com.wujunshen.algorithm.leetcode.basic;

/**
 * @author frank woo(吴峻申) <br>
 *     email:<a href="mailto:frank_wjs@hotmail.com">frank_wjs@hotmail.com</a> <br>
 * @date 2022/7/25 10:52<br>
 */
public class 搜索二维矩阵 {
  public boolean searchMatrix(int[][] matrix, int target) {
    int rows = matrix.length - 1;
    int columns = 0;
    while (rows >= 0 && columns < matrix[0].length) {
      int num = matrix[rows][columns];
      if (num == target) {
        return true;
      } else if (num > target) {
        rows--;
      } else {
        columns++;
      }
    }
    return false;
  }
}
